<template>
  <div class="orderCont" :style="'min-height: ' + docheight + 'px'">
    <div v-if="!showTimeOut && showCont">
      <div class="orderHead">
        <serch-com
          placher="请输入订单商品名称"
          @serchClick="serchFn"
          color="#4fc763"
        ></serch-com>
        <div class="orderTop">
          <div class="orderNav">
            <div
              :class="stepId == item.id ? 'navItem_active' : 'navItem'"
              @click="navFn(item)"
              :key="index"
              v-for="(item, index) in navArr"
            >
              {{ item.val }}
            </div>
          </div>
        </div>
      </div>
      <div class="orderList" v-if="orderList.length > 0">
        <div class="orderItem" :key="index" v-for="(item, index) in orderList">
          <div class="shopTop">
            <div class="shopNameCont">
              <div class="shopName">订单号:{{ item.order_number }}</div>
            </div>
            <div class="orderStatus">
              <span v-if="item.order_status == 1">待付款</span>
              <span v-if="item.order_status == 2">待接单</span>
              <span v-if="item.order_status == 3">待服务</span>
              <span v-if="item.order_status == 5">已完成</span>
              <span v-if="item.order_status == 6">已关闭</span>
              <span v-if="item.order_status == 7">已退款</span>
            </div>
          </div>
          <div class="goodsList">
            <div class="goodsItem" @click="toDetail(item)">
              <div class="flexCont">
                <div class="goodsImg">
                  <img :src="item.package_cover + ossSrc" />
                </div>
                <div class="goodsInfo">
                  <div class="goodsName">{{ item.package_name }}</div>
                  <div class="goodsType">
                    <div class="goodsTypeItem">
                      技师：{{ item.technician_nick_name }}
                    </div>
                    <div class="contNum">x{{ item.num }}</div>
                  </div>
                  <div class="orderTime">预约时间：{{ item.service_time }}</div>
                </div>
              </div>
              <div class="underInfo">
                <div class="userTitle">
                  订单信息
                </div>
                <div class="userForm">
                  <div class="userName">下单总费：</div>
                  <div class="userText">¥{{ item.order_total_price }}</div>
                </div>
                <div class="userForm">
                  <div class="userName">项目时长：</div>
                  <div class="userText">
                    {{ Number(item.package_time) * Number(item.num) }}分钟
                  </div>
                </div>
                <div class="userForm" v-if="item.jz_num">
                  <div class="userName">总计加钟：</div>
                  <div class="userText">{{ item.jz_num }}个</div>
                </div>
                <div class="userForm" v-if="item.jz_num">
                  <div class="userName">加钟费用：</div>
                  <div class="userText">¥{{ item.jz_money }}</div>
                </div>
              </div>
              <div class="underInfo" @click="toCenter(item)">
                <div class="userTitle">
                  客户信息
                </div>
                <div class="userForm">
                  <div class="userName">客户姓名：</div>
                  <div class="userText">{{ item.user_name }}</div>
                </div>
                <div class="userForm">
                  <div class="userName">联系电话：</div>
                  <div class="userText">{{ item.user_phone }}</div>
                </div>
                <div class="userForm">
                  <div class="userName">服务地址：</div>
                  <div class="userText">
                    {{ item.service_address }}{{ item.house_number }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="loadMore" v-if="isChageNav">数据请求中~</div>
      <div class="loadMore" v-if="orderList.length > 0 && !isChageNav">
        {{ loadMoreText }}
      </div>
      <nodata
        v-if="orderList.length == 0 && !isChageNav"
        text="暂无该类订单~"
      ></nodata>
    </div>
    <toast
      v-model="showToast"
      position="middle"
      width="50%"
      type="text"
      :time="1000"
      >{{ showText }}</toast
    >
    <getLoad v-if="!showCont"></getLoad>
    <getTimeOut v-if="showTimeOut"></getTimeOut>
    <sub-load v-if="showLoad"></sub-load>
  </div>
</template>

<script>
import nodata from "@/components/public/nodata";
import serchCom from "@/components/public/serchCom.vue";
import SaveBtn from "@/components/public/saveBtn.vue";

import { orderList } from "@/http/api";
import { Toast, Confirm } from "vux";
import getLoad from "@/components/public/getLoad";
import subLoad from "@/components/public/subLoad.vue";

import getTimeOut from "@/components/public/getTimeOut";
import { query } from "quill";
export default {
  components: {
    SaveBtn,
    subLoad,
    getLoad,
    getTimeOut,
    nodata,
    serchCom,
    Toast,
    Confirm
  },
  data() {
    return {
      loadMoreText: "数据加载中~",
      isChageNav: false,
      showLoad: false,
      showTimeOut: false,
      showCont: false,
      navArr: [
        { val: "全部", id: 0 },
        // { val: "待付款", id: 1 },
        { val: "待接单", id: 2 },
        { val: "待服务", id: 3 },
        { val: "已完成", id: 5 }
      ],
      showText: "",
      showToast: false,
      serchKey: "",
      stepId: 0,
      per_page: 10,
      page: 1,
      orderList: [],

      showConfirm: false,
      activeOrder: {},
      activeIndex: 0,
      ctrlId: 0,
      // 分页
      getting: false,
      last_page: 0,
      maskTitle: "",
      maskTipCont: "",
      maskTipMoney: "",
      maskBtnCont: ""
    };
  },
  methods: {
    toCenter(item) {
      this.$router.push({ path: "/userCenter", query: { id: item.user_id } });
    },
    serchFn(val) {
      this.serchKey = val;
      this.page = 1;
      this.last_page = 0;
      this.orderList = [];
      this.getData();
    },
    navFn(item) {
      this.stepId = item.id;
      this.orderList = [];
      this.page = 1;
      this.getData();
    },
    toDetail(item) {},
    getData() {
      let data = {
        order_status: this.stepId,
        package_name: this.serchKey,
        per_page: this.per_page,
        page: this.page
      };
      this.isChageNav = true;
      orderList(data)
        .then(res => {
          if (res.data.code == 1) {
            let arr = res.data.data.data;
            for (let i = 0; i < arr.length; i++) {
              this.orderList.push(arr[i]);
            }
            setTimeout(() => {
              this.getting = false;
            }, 100);
            this.last_page = res.data.data.last_page;
            if (this.page == this.last_page) {
              this.loadMoreText = "到底啦～";
            } else {
              this.loadMoreText = "数据加载中~";
            }
          } else {
            this.showToast = true;
            this.showText = "订单获取失败";
          }
          this.showCont = true;
          this.isChageNav = false;
        })
        .catch(() => {
          this.showCont = true;
          this.showTimeOut = true;
        });
    },
    nextfn() {
      if (this.$route.path == "/history") {
        let h =
          document.documentElement.scrollHeight || document.body.scrollHeight;
        let wh =
          document.documentElement.clientHeight || document.body.clientHeight;
        let top = document.documentElement.scrollTop || document.body.scrollTop;
        let bottom = h - wh - top;
        if (bottom <= 50) {
          if (this.getting == false) {
            if (this.last_page > this.page) {
              this.getting = true;
              this.page++;
              this.getData();
            }
          }
        }
      }
    }
  },
  mounted() {
    window.addEventListener("scroll", this.nextfn);
  },
  created() {
    this.getData();
  }
};
</script>

<style scoped lang="less">
.orderCont {
  width: 100%;
  background-color: #f2f3f3;
  box-sizing: border-box;
  padding-bottom: 0.75rem;
  padding-top: 6.5rem;
  .orderHead {
    width: 100%;
    background-color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;

    .orderTop {
      width: 100%;
      padding: 0 4%;
      box-sizing: border-box;
      background-color: #fff;
      .orderNav {
        width: 100%;
        display: flex;
        position: relative;
        justify-content: space-between;
        .navItem,
        .navItem_active {
          width: 20%;
          text-align: center;
          padding: 0.75rem;
          box-sizing: border-box;
          font-size: 0.75rem;
          color: #666;
          white-space: nowrap;
        }
        .navItem_active {
          color: #4fc763;
          border-bottom: 1px solid #4fc763;
        }
      }
    }
  }
  .orderList {
    width: 100%;
    padding: 0.25rem 4%;
    box-sizing: border-box;
    .orderItem {
      width: 100%;
      background-color: #fff;
      margin-bottom: 0.75rem;
      border-radius: 0.25rem;
      padding: 0 0.75rem 1rem;
      box-sizing: border-box;
      .shopTop {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        .shopNameCont {
          flex: 1;
          width: 0.5rem;
          display: flex;
          padding: 0.75rem 0;
          align-items: center;
          margin-right: 0.5rem;
          .shopicon {
            font-size: 1.1rem;
            margin-right: 0.25rem;
          }
          .shopName {
            font-size: 0.7rem;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .icon-jinrujiantou {
            font-size: 0.8rem;
            position: relative;
          }
        }
        .orderStatus {
          font-size: 0.6rem;
          color: #4fc763;
        }
      }
      .goodsList {
        width: 100%;
        .goodsItem {
          width: 100%;
          margin-bottom: 0.5rem;

          .flexCont {
            display: flex;
            align-items: center;
            .goodsImg {
              width: 4rem;
              height: 4rem;
              overflow: hidden;
              border-radius: 0.25rem;
              margin-right: 0.5rem;
              img {
                width: 100%;
              }
            }
            .goodsInfo {
              width: 0.5rem;
              flex: 1;
              display: flex;
              flex-direction: column;
              height: 4rem;
              justify-content: space-between;
              .goodsName {
                width: 100%;
                line-height: 1rem;
                font-size: 0.7rem;
                overflow: hidden; //超出的文本隐藏
                text-overflow: ellipsis; //溢出用省略号显示
                white-space: nowrap;
              }
              .orderTime {
                font-size: 0.6rem;
                color: #666;
              }
              .goodsType {
                display: flex;
                align-items: center;
                justify-content: space-between;
                .goodsNumCont {
                  display: flex;
                  height: 1rem;
                  line-height: 1rem;
                  color: #999;
                  font-size: 0.6rem;
                  align-items: center;
                }
                .goodsTypeItem {
                  padding: 0.1rem 0.5rem;
                  background-color: #f6f6f6;
                  font-size: 0.6rem;
                  height: 1rem;
                  line-height: 1rem;
                  border-radius: 0.15rem;
                  color: #999;
                }
                .contNum {
                  color: #666;
                }
                .userBtn {
                  padding: 0.25rem 0.75rem;
                  font-size: 0.6rem;
                  background-color: #4fc763;
                  color: #fff;
                  border-radius: 1rem;
                }
              }
              .goodsInfoPrice {
                color: #999;
                font-size: 0.6rem;
                display: flex;
                justify-content: space-between;
                align-items: center;
              }
            }
          }
          .underInfo {
            border-top: 1px dashed #ddd;
            margin-top: 0.75rem;
            padding-top: 0.75rem;
            .userTitle {
              font-weight: bold;
            }
            .userForm {
              display: flex;
              align-items: flex-start;
              margin-top: 0.25rem;
              justify-content: space-between;
              .userText {
                color: #666;
              }
            }
          }
        }
      }
      .orderSumCont {
        font-size: 0.6rem;
        text-align: right;
        color: #333;
        .priceVal {
          position: relative;
          top: 0.1rem;
          color: #4fc763;
        }
      }
      .orderTip {
        font-size: 0.6rem;
        color: #999;
        text-align: right;
        margin-top: 0.5rem;
      }
      .goodsCtrl {
        width: 100%;
        display: flex;
        align-items: center;
        margin-top: 0.75rem;
        justify-content: flex-end;
        .orderBtn {
          padding: 0.35rem 0;
          width: 25%;
          text-align: center;
          border-radius: 1rem;
          font-size: 0.6rem;
          box-sizing: border-box;
          margin-left: 0.5rem;
        }
        .greenBtn {
          border: 1px solid #4fc763;
          color: #4fc763;
        }
        .pinkBtn {
          border: 1px solid #4fc763;
          color: #4fc763;
        }
        .blackBtn {
          border: 1px solid #999;
          color: #666;
        }
      }
      .orderDes {
        border-top: 1px dashed #ebebeb;
        padding-top: 0.75rem;
        color: #666;
        font-size: 0.6rem;
      }
    }
  }
  .loadMore {
    text-align: center;
    padding: 0.75rem 0;
    font-size: 0.6rem;
    color: #999;
  }
  .orderMask {
    padding: 0.75rem;
    box-sizing: border-box;
    .maskTitle {
      font-size: 0.8rem;
      font-weight: bold;
      text-align: center;
    }
    .maskTip {
      margin-top: 0.5rem;
      line-height: 1.1rem;
    }
  }
}
</style>
